package edu.isquen.core.role.model;

import java.util.Collection;
import java.util.Set;

import edu.isquen.core.base.model.ValueObject;
import edu.isquen.core.user.model.User;
import edu.isquen.core.user.service.UserService;
import edu.isquen.util.factory.ServiceFactory;

/**
 * Role entity.
 * 
 * @author MyEclipse Persistence Tools
 */

public class Role extends ValueObject implements java.io.Serializable {

	private static final long serialVersionUID = -8234867943542073693L;
	private String id;
	private String name;
	private String engname;
	private String sortId;
	private String description;

	private Collection<User> users;

	/** default constructor */
	public Role() {
	}

	/** full constructor */
	public Role(String name, String engname, String sortId, String description,
			Set<User> users) {
		this.name = name;
		this.engname = engname;
		this.sortId = sortId;
		this.description = description;
		// this.users = users;
	}

	public Collection<User> getUsers() {
		try {
			if (users == null) {
				UserService uprocess = (UserService) ServiceFactory.createProcess(UserService.class);
				users=uprocess.getUsersByRole(this.getId());
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return users;
	}

	public void setUsers(Collection<User> users) {
		this.users = users;
	}
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEngname() {
		return this.engname;
	}

	public void setEngname(String engname) {
		this.engname = engname;
	}

	public String getSortId() {
		return this.sortId;
	}

	public void setSortId(String sortId) {
		this.sortId = sortId;
	}
}